#include<iostream>
#include"newton.h"

// 定义要进行插值的函数
class Function1 : public FunctionBase
{
public:
    double operator()(double x)  {
        return 1.0 / (1 + x * x);
    }
};

int main() {
    Function1 f;

    // 初始化数据点数组
    double nodes1[3] = {-5, 0, 5};
    double nodes2[5] = {-5, -2.5, 0, 2.5, 5};
    double nodes3[7] = {-5, -10/3.0, -5/3.0, 0, 5/3.0, 10/3.0, 5};
    double nodes4[9] = {-5, -15/4.0, -5/2.0, -5/4.0, 0, 5/4.0, 5/2.0, 15/4.0, 5};

    // 创建插值器对象
    NewtonInterpolator<Function1> interpolator1(nodes1, 3, f);
    NewtonInterpolator<Function1> interpolator2(nodes2, 5, f);
    NewtonInterpolator<Function1> interpolator3(nodes3, 7, f);
    NewtonInterpolator<Function1> interpolator4(nodes4, 9, f);

    // 获取并输出插值器的差分系数
    double* coefficients1 = interpolator1.getCoefficients();
    double* coefficients2 = interpolator2.getCoefficients();
    double* coefficients3 = interpolator3.getCoefficients();
    double* coefficients4 = interpolator4.getCoefficients();

    for (int i = 0; i < 3; ++i) {
        std::cout << coefficients1[i] << ' ';
    }
    std::cout << std::endl;

    for (int i = 0; i < 5; ++i) {
        std::cout << coefficients2[i] << ' ';
    }
    std::cout << std::endl;

    for (int i = 0; i < 7; ++i) {
        std::cout << coefficients3[i] << ' ';
    }
    std::cout << std::endl;

    for (int i = 0; i < 9; ++i) {
        std::cout << coefficients4[i] << ' ';
    }
    std::cout << std::endl;

    return 0;
}
